package com.automannn.websoketmqtt.provider.config;

import com.automannn.websoketmqtt.common.amqp.TopicGlobalValue;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenkh
 * @time 2020/10/13 11:16
 */
@Configuration
public class TopicRabbitConfig {

    /**
     * 队列配置
     * @return
     */
    @Bean
    public Queue firstQueue(){
        return  new Queue(TopicGlobalValue.MAN);
    }

    /**
     * 队列配置
     */
    @Bean
    public Queue secondQueue(){
        return new Queue(TopicGlobalValue.WOMAN);
    }

    /**
     * 交换机配置
     */
    @Bean
    public TopicExchange automannnTopicExchange(){
        return new TopicExchange(TopicGlobalValue.TOPIC_EXCHANGE_NAME);
    }

    /**
     * 绑定 严格路由键
     */
    @Bean
    public Binding bindingTopicExchangeMessage1(){
        return BindingBuilder.bind(firstQueue()).to(automannnTopicExchange()).with(TopicGlobalValue.MAN);
    }

    /**
     * 绑定
     */
    @Bean
    public Binding bindingTopicExchangeMessage2(){
        return BindingBuilder.bind(secondQueue()).to(automannnTopicExchange()).with(TopicGlobalValue.TOPIC_FLAG+".#");
    }


}
